package com.book.lizhi.adapter;

import java.util.List;
import java.util.Random;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import cn.waps.AppConnect;

import com.book.lizhi.model.AdModel;

public abstract class AdAppAdapter extends AppAdapter {
	private Context mContext;
	private List mList;

	public AdAppAdapter(Context context, List list) {
		super(context, list);
		mContext = context;
		mList = list;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (getItemViewType(position) == 0) {
			LinearLayout linearLayout = new LinearLayout(mContext);
			AppConnect.getInstance(mContext).showBannerAd(mContext, linearLayout);
			return linearLayout;
		}
		return super.getView(position, convertView, parent);
	}

	@Override
	public int getItemViewType(int position) {
		if (getItem(position) instanceof AdModel) {
			return 0;
		}
		return 1;
	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public void notifyDataSetChanged() {
		if (mList.size() > 0) {
			Random random = new Random();
			int i = random.nextInt(mList.size());
			mList.add(i, new AdModel());

		}

		super.notifyDataSetChanged();
	}
}
